//shiftguard.txt - Like a regular guard, but stands still. When a certain flag
//   is non-zero, creature shift to a different spot
//Cell 0 - Nav point to shift to.
//Cell 1 - Number of state when talked to. Plays default text if left at 0.
//Cell 2 - Do text bubbles? If > 0, no.
// Cell 3,4 - stuff done flag. When > 0, creature shifts to that spot.

begincreaturescript;

variables;

short i,target;

body;

beginstate INIT_STATE;
	break;

beginstate DEAD_STATE;
break;

beginstate START_STATE; // going on patrol
	// if I have a target for some reason, go attack it
	if (target_ok()) {
		if (dist_to_char(get_target()) <= 16)
			set_state(3);
			else set_foe_target(ME,-1);
		}

	if (get_foe_target(ME,6,0)) {
		do_attack();
		set_state(3);
		}
	if (who_shot_me() >= 0) {
		set_foe_target(ME,who_shot_me());
		do_attack();
		set_state(3);
		}

	if (get_memory_cell(2) == 0) {
		if (current_zone() == 2) {
			if (get_ran(1,0,100) < 10)
				create_text_bubble("Keep alert.");
				else if (get_ran(1,0,100) < 10)
					create_text_bubble("Watch out for rogues.");	
			}
			else {
				if (get_ran(1,0,100) < 10)
					create_text_bubble("Yawn.");
					else if (get_ran(1,0,100) < 10)
						create_text_bubble("Stay alert.");
				}
		}

	if ((get_flag(get_memory_cell(3),get_memory_cell(4)) > 0) &&
	  (dist_to_nav_point(ME,get_memory_cell(0)) > 1)) {
		approach_nav_point(ME,get_memory_cell(0),1);
		}
		else if (get_flag(get_memory_cell(3),get_memory_cell(4)) == 0)
			return_to_start(ME,0);

	if (am_i_doing_action() == FALSE)
		end_combat_turn();

break;

beginstate 3; // attacking
	if (my_dist_from_start() >= 16) {
		set_foe_target(ME,-1);
		return_to_start(ME,0);
		set_state(START_STATE);
		}
	if (target_ok() == FALSE)
		set_state(START_STATE);
	do_attack();
break;


beginstate TALKING_STATE;
	if (get_memory_cell(1) == 0) {
		print_str("You try to start a conversation with the guard, but it pays no");
		print_str("  attention to you. The guard is serious about its duties.");
		}
		else begin_talk_mode(get_memory_cell(1));
break;